import {
	createRouter,
	createWebHashHistory,
	useRoute
} from 'vue-router'

import { staticRoutes } from './staticRoutes'
import dynamicRoutes from './dynamicRoutes'
import {
	useStore
} from '@/store/store'

const routes = staticRoutes.concat(dynamicRoutes)


 
const router = createRouter({
	history: createWebHashHistory(),
	routes
})


router.beforeEach((to, from, next) => {
	
	const token = localStorage.getItem('token')
	if (to.path === '/login') {
		next()
	} else {
		if (token) {
			useStore().token = token;
			next()
		} else {
			next({
				path: '/login'
			})
		}
	}
})

export default router

